package com.zhongfl.crm.service.impl;

import com.github.pagehelper.PageHelper;
import com.heptagram.lixiao.bean.enums.OpportunityStage;
import com.zhongfl.crm.mapper.LxCustomerOrderMapper;
import com.zhongfl.crm.model.LxCustomerOrder;
import com.zhongfl.crm.model.OrderType;
import com.zhongfl.crm.request.LxCustomerOrderRequest;
import com.zhongfl.crm.service.LxCustomerOrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author wang.yuchuan
 * @date 2018/9/19
 */
@Service
public class LxCustomerOrderServiceImpl implements LxCustomerOrderService {

    @Resource
    private LxCustomerOrderMapper lxCustomerOrderMapper;

    /**
     * 查询全部励销客户订单业务
     * @return 励销客户订单对象集合
     */
    @Override
    public List<LxCustomerOrder> findAllLxCustomerOrder() {
        List<LxCustomerOrder> lxCustomerOrders = lxCustomerOrderMapper.selectAllLxCustomerOrder();
        return lxCustomerOrders;
    }

    /**
     * 分页查询励销客户订单业务
     * @param lxCustomerOrderRequest 分页查询对象
     * @return 客户订单对象集合
     */
    @Override
    public List<LxCustomerOrder> findLxCustomerOrderByPage(LxCustomerOrderRequest lxCustomerOrderRequest) {
        PageHelper.startPage(lxCustomerOrderRequest.getPage(),lxCustomerOrderRequest.getPageSize());
        List<LxCustomerOrder> lxCustomerOrders = lxCustomerOrderMapper.selectLxCustomerOrderByPage(lxCustomerOrderRequest);

        return lxCustomerOrders;
    }

    /**
     * 查询全部订单状态业务
     * @return 订单状态对象集合
     */
    @Override
    public List<OrderType> findAllStage() {
        List<OrderType> orderTypes = new ArrayList<>();
        for (OpportunityStage stage : OpportunityStage.values()) {
            orderTypes.add(new OrderType(stage.getId(),stage.getValue()));
        }
        return orderTypes;
    }

    /**
     * 按照客户订单ID查询订单详情业务
     * @param id 客户订单ID
     * @return 客户订单数据对象
     */
    @Override
    public LxCustomerOrder findById(Long id) {
        LxCustomerOrder lxCustomerOrder = lxCustomerOrderMapper.selectLxCustomerOrderById(id);
        return lxCustomerOrder;
    }

    /**
     * 删除一条业务
     *
     * @param id 客户订单ID
     */
    @Override
    public void deleteById(Long id) {
        lxCustomerOrderMapper.deleteById(id);
    }

    /**
     * 插入一条业务
     *
     * @param saveCustomerOrder 客户订单对象
     */
    @Override
    public void insert(LxCustomerOrder saveCustomerOrder) {
        lxCustomerOrderMapper.insert(saveCustomerOrder);
    }

    /**
     * 修改一条记录
     *
     * @param updateCustomerOrder 客户订单对象
     */
    @Override
    public void updateById(LxCustomerOrder updateCustomerOrder) {
        lxCustomerOrderMapper.updateById(updateCustomerOrder);
    }

    /**
     * 按励销渠道id查询客户订单
     * @param lxCustomerOrderRequest
     * @return
     */
    @Override
    public List<LxCustomerOrder> findLxCustomerOrderByCustomerId(LxCustomerOrderRequest lxCustomerOrderRequest) {
        PageHelper.startPage(lxCustomerOrderRequest.getPage(),lxCustomerOrderRequest.getPageSize());
        return lxCustomerOrderMapper.findLxCustomerOrderByCustomerId(lxCustomerOrderRequest);
    }
}
